/* ************************************************************************
> File Name:     2.c
> Author:        zhfu
> mail:          3346897597@qq.com
> Created Time:  2022年04月26日 星期二 10时46分00秒
> Description:   
 ************************************************************************/
#include<stdio.h>
#include<stddef.h>

char *shrink_space(char *dest, const char *src, size_t n)
{
    char *d = dest;
    int i, key = 0;
    for (i = 0; i < n && src[i] != '\0'; ++i){
        char s = src[i];
        if (s == ' ' || s == '\t' || s == '\n'){
            if (!key){
                *dest++ = ' ';
                key = 1;
            }
        }
        else{
            *dest++ = src[i];
            key = 0;
        }
    }
    return d;
}

int main(){
    char s[] = "This Content hoho       is ok\n\tok?\n\tfile system\nuttered words   ok ok      ?\nend.";
    char ret[100];

    printf("%s\n", shrink_space(ret, s, sizeof(ret)));

    return 0;
}
